﻿Imports Publics

Public Class Frm_DieuKienLoc_ChonNhomVatTu
    Private _lstID As New List(Of String)
    Public Property lstID() As List(Of String)
        Get
            Return _lstID
        End Get
        Set(ByVal value As List(Of String))
            _lstID = value
        End Set
    End Property

    Private _Thoat As Boolean = False
    Public Property Thoat() As Boolean
        Get
            Return _Thoat
        End Get
        Set(ByVal value As Boolean)
            _Thoat = value
        End Set
    End Property
    Private lstSource As New List(Of clsDMChon)
    Private Flag As Boolean
    Private Sub btnThoat_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnThoat.ItemClick
        Thoat = True
        Me.Close()
    End Sub

    Private Sub btnChon_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnChon.ItemClick
        grvData.FocusedRowHandle += 1
        lstID = (From ds In lstSource Where ds.Chon Select ds.ID).ToList
        If lstID.Count > 0 Then
            Thoat = False
            Me.Close()
        Else
            MsgInfo("Bạn phải chọn ít nhất một kho")
        End If
    End Sub

    Private Sub Frm_DieuKienLoc_ChonNhomSanPham_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        'Chọn
        If e.KeyCode = Windows.Forms.Keys.Enter Then
            btnChon_ItemClick(Nothing, Nothing)
        ElseIf clsDSPhimTatDefault.isCheckPhimTat(e, ELoaiPhimTat.pSELECT_UNSELECT_ALL) Then
            'Chọn
            If Flag = False Then
                Flag = True
            Else    'Bỏ chọn
                Flag = False
            End If
            For i = 0 To grvData.RowCount - 1
                grvData.SetRowCellValue(i, grdColChon, Flag)
            Next
            grdData.RefreshDataSource()
        ElseIf clsDSPhimTatDefault.isCheckPhimTat(e, ELoaiPhimTat.pEXIT, btnThoat) Then
            btnThoat_ItemClick(Nothing, Nothing)
        ElseIf e.KeyCode = Windows.Forms.Keys.Space Then
            If grvData.FocusedColumn IsNot Nothing AndAlso grvData.FocusedColumn.Equals(grdColChon) Then Return
            Dim index = grvData.FocusedRowHandle
            If index >= 0 Then
                Dim value As Boolean = grvData.GetRowCellValue(index, grdColChon)
                grvData.SetRowCellValue(grvData.FocusedRowHandle, grdColChon, Not value)
            End If
        End If
    End Sub

    Private Sub Frm_DieuKienLoc_ChonNhomSanPham_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        FillDataToGrid()
    End Sub

    Private Sub FillDataToGrid()
        lstSource = (From ds In dbTV.VT_DM_NhomVatTus Where ds.InUsed _
                     Order By ds.MaNhom Select New clsDMChon With { _
                     .ID = ds.ID, .Ma = ds.MaNhom, .Ten = ds.TenNhom, .Chon = lstID.Contains(ds.ID)}).ToList
        grdData.DataSource = lstSource
        grdData.RefreshDataSource()
    End Sub
End Class